#include<bits/stdc++.h>

using namespace std;

int main() {
    int n, q;
    cin >> n >> q;
    vector<priority_queue<int>> Q(n);
    while (q--) {
        int op, t, x;
        cin >> op >> t;
        if (op == 0) {
            cin >> x;
            Q[t].push(x);
        } else if (op == 1) {
            if (Q[t].empty())continue;
            cout << Q[t].top() << endl;
        } else {
            if (Q[t].empty()) continue;
            Q[t].pop();
        }
    }
    return 0;
}